<?php
$this->breadcrumbs = array(
    'Jobs' => array('index'),
    'Manage',
);

Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
	$('.search-form').toggle();
	return false;
});
$('.search-form form').submit(function(){
	$.fn.yiiGridView.update('person-date-grid', {
		data: $(this).serialize()
	});
	return false;
});
");
?>

<?php
$this->renderPartial('_menu', array(
    'model' => $model,
));
$this->widget('application.extensions.fancybox.EFancyBox', array('target' => 'a.iframe','config' => array('width'=>800,'height'=>600)));
?>

<h1><?=$title?></h1>

<p>
    You may optionally enter a comparison operator (<b>&lt;</b>, <b>&lt;=</b>, <b>&gt;</b>, <b>&gt;=</b>, <b>&lt;&gt;</b>
    or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.
</p>

<?php echo CHtml::link('Advanced Search', '#', array('class' => 'search-button')); ?>
<div class="search-form" style="display:none">
    <?php
    $this->renderPartial('_search', array(
        'model' => $model,
    ));
    ?>
</div><!-- search-form -->

<?php
$columns = array(
    'pdid' => array(
        'name' => 'pdid',
        'header' => 'ID',
        'headerHtmlOptions' => array('width' => '6%'),
        'htmlOptions' => array('style' => 'text-align:center;')
    ),
    'username' => array(
        'name' => 'user.username',
        'header' => 'User',
        'headerHtmlOptions' => array('width' => '8%'),
        'htmlOptions' => array('style' => 'text-align:center;')
    ),
    'job' => array(
        'name' => 'job',
        'header' => 'Job',
        'headerHtmlOptions' => array('width' => '18%'),
    ),
    'uid' => array(
        'name' => 'uid',
        'header' => '用户ID',
        'headerHtmlOptions' => array('width' => '8%'),
        'htmlOptions' => array('style' => 'text-align:center;')
    ),
    'type' => array(
        'name' => 'type',
        'header' => 'Periodic',
        'headerHtmlOptions' => array('width' => '10%'),
        'htmlOptions' => array('style' => 'text-align:center;')
    ),
    'time' => array(
        'name' => 'time',
        'header' => 'Job开始时间',
        'headerHtmlOptions' => array('width' => '15%'),
        'htmlOptions' => array('style' => 'text-align:center;')
    ),
    'style' => array(
        'name' => 'style',
        'header' => 'Type',
        'headerHtmlOptions' => array('width' => '10%'),
        'htmlOptions' => array('style' => 'text-align:center;')
    ),
    array(
        'class' => 'CButtonColumn',
        'header' => '操作',
        'headerHtmlOptions' => array('width' => '100px'),
        'template' => '{view}{update}{delete}{recycle}',
        'buttons' => array(
            'recycle' => array(
                'label' => 'assign',
                'imageUrl' => Yii::app()->baseUrl . '/images/manman.png',
                'url' => 'Yii::app()->controller->createUrl("personDate/assignTask",array("id"=>$data->pdid))',                
            ),
        ),		
    ),
);
if($jobStatus==100){//如果是template，则多一个从这个template创建新job的按钮
    $columns[] = array(
        'class' => 'CLinkColumn',
        'header' => '', //显示表名称
        'headerHtmlOptions' => array('width' => '5%'),
        'labelExpression' => '创建', //显示名称
        'urlExpression' => 'Yii::app()->createUrl("personDate/TemplateInt",array("id"=>$data->pdid))', //显示URL
//            'urlExpression' => 'Yii::app()->createUrl("personTask/view",array("id"=>$data->ptid))', //显示URL
        'linkHtmlOptions' => array('class' => 'iframe'),
        'htmlOptions' => array('style' => 'text-align:center;'),
    );
}elseif($jobStatus==0){
    $columns[] = array(
        'class' => 'CCheckBoxColumn',
        'name' => 'pdid',
        'id' => 'jobSelect',
        'selectableRows' => 2,
        'footer' => '<button type="button" onclick="GetCheckbox();" >Done</button>',
        'htmlOptions' => array('style' => 'text-align:center;'),
    );
}
$this->widget('zii.widgets.grid.CGridView', array(
	'afterAjaxUpdate'=>"function(id,data){ $('a.iframe').fancybox({'width':800,'height':600}); }",
    'id' => 'person-date-grid',
    'dataProvider' => $model->search($jobStatus),
    'filter' => $model,
    'columns' => $columns,
));
?>
<script type="text/javascript">
    /*<![CDATA[*/
    var GetCheckbox = function (){
        var data=new Array();
        $("input:checkbox[name='jobSelect[]']").each(function (){
            if($(this).attr("checked")=='checked'){
                data.push($(this).val());
            }
        });
        if(data.length > 0){
            $.post('<?php echo CHtml::normalizeUrl(array('/personDate/doneJob')); ?>',{'jobSelect[]':data}, function (data) {
                var ret = $.parseJSON(data);
                if (ret != null && ret.success != null && ret.success) {
                    alert(ret.msg);
                    window.location.href = '<?php echo CHtml::normalizeUrl(array('/personDate/index')); ?>';
                }
            });
        }else{
            alert("请选择要关闭的Job!");
        }
    }
    /*]]>*/
</script>